<%@ Page Language="VB" StylesheetTheme="Default" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="QuestionnairePerm.aspx.vb" Inherits="Modules_Questionnaires_Management_QuestionnairePerm" title="Questionnaire Permission Editor Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

  <table id="Table2" cellpadding="2" cellspacing="2" width="100%">
        <tr>
            <td colspan="3">
                <strong><font size="2">
                    <asp:Label ID="lblHeader" runat="server" Text="QUESTIONNAIRE PERMISSION EDITOR"></asp:Label></font></strong>
            </td>
            <td align="right" colspan="1" style="width: 130px">
                &nbsp;<asp:LinkButton ID="lbBack" runat="server" ForeColor="Blue">back</asp:LinkButton></td>
        </tr>
        <tr>
            <td colspan="4" valign="top">
                <hr size="1" width="100%" /><br /></td>
        </tr>
      <tr>
          <td rowspan="3" valign="top" width="15" height="400">
              &nbsp;</td>
          <td valign="top">
            <table>
                <tr>
                    <td align="right">
                        <strong>Study ID:</strong>
                    </td>
                    <td>
                        <asp:Label ID="lblStudyID" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <strong>Instrument:</strong>
                    </td>
                    <td>
                        <asp:Label ID="lblInstrument" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <strong>Description:</strong>
                    </td>
                    <td>
                        <asp:Label ID="lblDescription" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>
          </td>
          <td colspan="2" valign="top">
          </td>
      </tr>
      <tr>
          <td valign="top">&nbsp;
          </td>
          <td colspan="2" valign="top">
          </td>
      </tr>
        <tr>
            <td valign="top">
                <table cellpadding=0 cellspacing=0>
    <tr>
        <td id="tbf1" runat="server">
        </td>
        <td id="tbf2" runat="server">
            <asp:Label ID="lblf" runat="server" Text="Taking Permission" Font-Bold="True" ForeColor="WhiteSmoke"></asp:Label>
            <asp:LinkButton ID="lbf" runat="server" Visible=false CssClass="WhiteLink">Taking Permission</asp:LinkButton>
        </td>
        <td id="tbf3" runat="server" width="10">
        </td>
        <td id="tbf4" runat="server">
        </td>
        <td id="tbb2" runat="server">
            <asp:Label ID="lblb" runat="server" Text="Editing Permission" Font-Bold="True" ForeColor="WhiteSmoke" Visible=false></asp:Label>
            <asp:LinkButton ID="lbb" runat="server" CssClass="WhiteLink">Editing Permission</asp:LinkButton>
        </td>
        <td id="tbb3" runat="server" width="10">
        </td>
        <td id="Tbb4" runat="server">
        </td>
    </tr>

</table>
<table id="tbl" runat="server"  cellspacing="5" width=500 height=100>
    <tr>
        <td align="right">
                <asp:CheckBox ID="cbShowOnlyAssignedRoles" runat="server" AutoPostBack="True" 
                    Text="Show Assigned Roles Only" TextAlign="Left" CausesValidation="True" /></td>
    </tr>
    <tr>
        <td>
                <asp:GridView ID="gvRoles" runat="server" AutoGenerateColumns="False" DataSourceID="odsRoles" Width="100%" PageSize="100" ShowHeader="False">
                    <Columns>
                        <asp:TemplateField SortExpression="RoleName" HeaderText="Roles">
                            <ItemTemplate>
                                <asp:CheckBox ID="cbAllowed" runat="server" Checked='<%# Bind("Allowed") %>' Text='<%# Bind("RoleName") %>'
                                 Enabled='<%# not Eval("Locked") %>' onClick='IsChanged(this);' />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <asp:ObjectDataSource ID="odsRoles" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetRoles"
                    TypeName="DotNetPM.Business.Questionnaire.QuestionnaireODS">
                    <SelectParameters>
                        <asp:SessionParameter DefaultValue="" Name="questionnaireId" SessionField="questionnaire_questionnaireId"
                            Type="Int32" />
                        <asp:ControlParameter ControlID="lblb" Name="isEditingPermission"
                            PropertyName="Visible" Type="Boolean" />
                        <asp:ControlParameter ControlID="cbShowOnlyAssignedRoles" Name="showOnlyAssignedRoles"
                            PropertyName="Checked" Type="Boolean" />
                    </SelectParameters>
                </asp:ObjectDataSource>
</td>
    </tr>
    <tr>
        <td align="right">
            <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="confirmNotSave"></asp:CustomValidator>
            <asp:Button ID="butSave" runat="server" Text="Save" Enabled="False" EnableViewState="False" CausesValidation="False" Width="60px" />&nbsp;
            <asp:Button ID="butCancel" runat="server" Text="Cancel" Width="60px" />
        </td>
    </tr>
</table>
                &nbsp;&nbsp;
            </td>
            
            <td colspan="2"  valign="top" height="380">
                &nbsp;
            </td>
        </tr>
    </table>
    
    
<script type="text/javascript">
    function IsChanged(source){
        var gridId = source.id.substring(0,source.id.length-16);
        var grid = document.all[gridId];
        var rows = grid.all;
        var curValue = "";
        var first = true;
        if ( rows != null ) {
            for ( i = 0; i < rows.length; i++ ) {
                if (rows.item(i).tagName == "INPUT") {
                    if ((rows.item(i).checked) && (rows.item(i).disabled == false)){
                        i++
                        if (first){
                            curValue = rows.item(i).innerText;
                            first = false;
                        } else {
                            curValue = curValue + "|" + rows.item(i).innerText;
                        }
                    }
                }
            }
        }
        document.all[butSaveId].disabled = (curValue==orgValue);
    }
    function confirmNotSave(sender, args){
        if (document.all[butSaveId].disabled==false){
            var resp;
            args.IsValid = confirm("The permission has changed. Do you want to continue without saving the changes?");
        }     
    }
</script>
</asp:Content>
